#include <iostream>
#include <math.h>
using namespace std;

typedef struct Node
{
    int digit;
    struct Node *top;
    struct Node *rear;
} Node, *NodeList;

int Len(NodeList &L)
{
    Node *p = L->rear;
    int length = 0;
    while (p != L)
    {
        p = p->rear;
        length++;
    }
    return length;
}

Node *Get(NodeList &L, int pos)
{
    Node *p = L;
    for (int i = 0; i < pos; i++)
    {
        p = p->rear;
    }
    return p;
}

void Insert(NodeList &L, int pos, int newDigit)
{
    int length = Len(L);
    if (pos < 0 || pos > length + 1)
    {
        cout << "Insert Position Out Of Bound" << endl;
        exit;
    }
    NodeList s = (NodeList)malloc(sizeof(Node));
    s->digit = newDigit;
    Node *p = Get(L, pos);
    p->top->rear = s;
    s->top = p->top;
    s->rear = p;
    p->top = s;
}

void Print(NodeList &L)
{
    Node *p = L;
    if (p->digit == -1)
    {
        cout << "-";
    }
    int count = 0;
    do
    {
        p = p->rear;
        cout << p->digit;
        count++;
        if (count % 4 == 0)
        {
            cout << " ";
        }
    } while (p->rear != L);
}

int Remove(Node *p)
{
    p->top->rear = p->rear;
    p->rear->top = p->top;
    int number = p->digit;
    free(p);
    return number;
}

void Init(NodeList &L)
{
    L->rear = L;
    L->top = L;
    L->digit = -2;
}

void Exchange(NodeList &List1, NodeList &List2)
{
    NodeList p = (NodeList)malloc(sizeof(Node));
    p = List1;
    List1 = List2;
    List2 = p;
}

int Del(NodeList &L, int pos)
{
    Node *p = Get(L, pos);
    return Remove(p);
}

int Pop(NodeList &L)
{
    return Remove(L->top);
}

void Append(NodeList &L, int newDigit)
{
    Insert(L, 0, newDigit);
}

void NewFirst(NodeList &L, int newDigit)
{
    Insert(L, 1, newDigit);
}

int Compare(NodeList &List1, NodeList &List2)
{
    // return 1 if List1 > List2, -1 if List1 < List2, 0 if List1 == List2
    Node *p1 = List1->rear;
    Node *p2 = List2->rear;
    int length1 = Len(List1);
    int length2 = Len(List2);
    if (length1 > length2)
    {
        return 1;
    }
    if (length1 < length2)
    {
        return -1;
    }
    while (p1 != List1 && p2 != List2)
    {
        if (p1->digit > p2->digit)
        {
            return 1;
        }
        if (p1->digit < p2->digit)
        {
            return -1;
        }
        p1 = p1->rear;
        p2 = p2->rear;
    }
    return 0;
}

void Trim(NodeList &List)
{
    Node *p = List->rear;
    while (p->digit == 0)
    {
        p = p->rear;
        Remove(p->top);
    }
}

void Add(NodeList &List1, NodeList &List2)
{
    Node *last1 = List1->top;
    Node *last2 = List2->top;
    Node *tmp_p = (NodeList)malloc(sizeof(Node));
    int tmp = 0;
    while (last2 != List2)
    {

        if (last1 == List1)
        {
            NewFirst(List1, last2->digit);
            last2 = last2->top;
            continue;
        }

        tmp = last1->digit + last2->digit;
        if (tmp < 10)
        {
            last1->digit = tmp;
        }
        else
        {
            tmp_p = last1;
            while (tmp > 0)
            {
                tmp_p->digit = tmp % 10;
                tmp /= 10;
                tmp_p = tmp_p->top;
                if (tmp_p == List1)
                {
                    NewFirst(List1, tmp);
                }
                else
                {
                    tmp += tmp_p->digit;
                }
            }
        }
        last1 = last1->top;
        last2 = last2->top;
    }
    Trim(List1);
}

void Substract_(NodeList &List1, NodeList &List2)
{
    Node *last1 = List1->top;
    Node *last2 = List2->top;
    Node *tmp_p = (NodeList)malloc(sizeof(Node));
    int tmp = 0;
    while (last2 != List2)
    {
        tmp = last1->digit - last2->digit;
        if (tmp >= 0)
        {
            last1->digit = tmp;
        }
        else
        {
            tmp_p = last1->top;
            while (1)
            {
                if (tmp_p->digit >= 1)
                {
                    tmp_p->digit--;
                    while (tmp_p->rear != last1)
                    {
                        tmp_p = tmp_p->rear;
                        tmp_p->digit += 9;
                    }
                    if (tmp_p != last1)
                    {
                        last1->digit = 10 + tmp;
                    }
                    break;
                }
                tmp_p = tmp_p->top;
            }
        }
        last1 = last1->top;
        last2 = last2->top;
    }
}

void Substract(NodeList &List1, NodeList &List2)
{
    int compare_result = Compare(List1, List2);
    if (compare_result == 0)
    {
        cout << 0 << endl;
        return;
    }
    if (compare_result < 0)
    {
        Exchange(List1, List2);
    }
    Substract_(List1, List2);
    if(compare_result < 0){
        List1->digit = -1;
    }
    Trim(List1);
}

int main()
{
    NodeList L1 = (NodeList)malloc(sizeof(Node));
    NodeList L2 = (NodeList)malloc(sizeof(Node));
    Init(L1);
    Init(L2);
    char tmp;
    char ope; // operator
    cout << "Enter Equation" << endl;
    while (cin >> tmp)
    {
        if (tmp < 48 || tmp > 57)
        {
            if (tmp == '+' || tmp == '-')
            {
                ope = tmp;
                break;
            }
            else
            {
                cout << "Unsupported Operator" << endl;
                exit;
            }
        }
        Append(L1, tmp - 48);
    }
    while (cin >> tmp)
    {
        if (tmp == '=')
        {
            break;
        }
        Append(L2, tmp - 48);
    }
    Trim(L1);
    Trim(L2);
    if (ope == '+')
    {
        Add(L1, L2);
    }
    else if (ope == '-')
    {
        Substract(L1, L2);
    }
    else
    {
        cout << "Unsupported Operator";
        exit;
    }
    Print(L1);
    return 0;
}